<?php
include_once("../DAO/UserDAO.php");
include_once("../Entities/User.php");
include_once("../Utility/WebUtilities.php");

if(WebUtilities::GetQueryString("hdSubmit", 0) == 1)
{
	$user = new User();
	$userDAO = new UserDAO();
	$user->Username = WebUtilities::GetQueryString("tbUsername", "");
	$user->Email = WebUtilities::GetQueryString("tbEmail", "");
	$user->Password = md5(WebUtilities::GetQueryString("tbPassword", ""));
	$user->FirstName = WebUtilities::GetQueryString("tbFirstName", "");
	$user->LastName = WebUtilities::GetQueryString("tbLastName", "");
	$user->Phone = WebUtilities::GetQueryString("tbPhone", "");
	$user->Role = 2;
	$userDAO->CreateUser($user);
	WebUtilities::Redirect("index.php");
}

$mainContent = "<form enctype='multipart/form-data' action='Register.php' method='POST'>
					<div class='center'>
						<h1>USER REGISTER</h1>
						<h2>English For Us</h2>
					</div>
					<hr />
					
					<label class='headerField'>Create a new system account</label><br /><br />
					<div class='oneRow'>
						<label class='left'>*Your Username : </label>
						<input name='tbUsername' class='right' type='text' id='tbUsername' /><label name='error' class='error' id='erUsername'>require</label><label name='error' class='error' id='erUsernameValid'>this username is used</label>
					</div>
					<div class='oneRow'>
						<label class='left'>&nbsp;</label>
						<label class='comment'>You'll use this as your system account</label>
					</div>
					<div class='oneRow'>
						<label class='left'>*Your email address : </label>
						<input name='tbEmail' class='right' type='text' id='tbEmail' /><label name='error' class='error' id='erEmail'>require</label>
					</div>
					<hr/>
					
					<label class='headerField'>Choose your password</label><br /><br />
					<div class='oneRow'>
						<label class='left'>*Type password : </label>
						<input name='tbPassword' class='right' type='password' id='tbPassword' onkeydown='checkPasswordLength(this)'/><label name='error' class='error' id='erPassword'>six-character minimum</label>
					</div>
					<div class='oneRow'>
						<label class='left'>&nbsp;</label>
						<label class='comment'>Six-character minimum; case sensitive</label>
					</div>
					<br/>
					<div class='oneRow'>
						<label class='left'>Password strength : </label>
						<input class='right' type='text' id='tbPasswordStrength' readonly='true' />
					</div>
					<div class='oneRow'>
						<label class='left'>*Retype Password : </label>
						<input name='require' class='right' type='password' id='tbConfirmPassword' /><label name='error' class='error' id='erConfirmPassword'>not match</label>
					</div>
					<hr/>
					
					<label class='headerField'>Your information</label><br/><br />
					<div class='oneRow'>
						<label class='left'>First name : </label>
						<input name='tbFirstName' class='right' type='text' id='tbFirstName' />
					</div>
					<div class='oneRow'>
						<label class='left'>Last name : </label>
						<input name='tbLastName' class='right' type='text' id='tbLastName' />
					</div>
					<div class='oneRow'>
						<label class='left'>Phone : </label>
						<input name='tbPhone' class='right' type='text' id='tbPhone' />
					</div>
					<hr/>
					
					<label class='headerField'>Type the characters you see in the picture</label><br /><br />
					<div class='oneRow'>
						<label class='left'>Picture :</label>
						<div style='float:left;margin-top:-15px;margin-left:250px;border-style:solid;'>
							<img style='margin-left:0px;' class='picConfirm' src='../confirmImages/1.jpg' id='pic1' />
							<img class='picConfirm' src='../confirmImages/1.jpg' id='pic2' />
							<img class='picConfirm' src='../confirmImages/1.jpg' id='pic3' />
							<img class='picConfirm' src='../confirmImages/1.jpg' id='pic4' />
							<img class='picConfirm' src='../confirmImages/1.jpg' id='pic5' />
							<img class='picConfirm' src='../confirmImages/1.jpg' id='pic6' />
							<img class='picConfirm' src='../confirmImages/1.jpg' id='pic7' />
							<img class='picConfirm' src='../confirmImages/1.jpg' id='pic8' />
						</div>
						<input type='hidden' id='hdCode' name='hdCode' />
						<a  href='#' id='btRefresh' class='btRefresh' onclick='return generateRandomCode()'></a>
					</div>
					<div class='oneRow'>
						<label class='left'>&nbsp;</label>
						<label class='comment'>8 characters , all characters is lower</label>
					</div>
					<div class='oneRow'>
						<label class='left'>*Type characters :</label>
						<input name='require' class='right' type='text' id='tbCharacters' /><label name='error' class='error' id='erCheckCode'>not match</label>
					</div>
					<hr/>
					
					<label class='headerField'>Review and accept the agreements</label><br/><br />
					<label>Clicking <b>I accept</b> means that you agree <a href='#'>Privacy statement</a></label><br/>
					<hr/>
					<input type='hidden' value='1' name='hdSubmit'/>
					<div class='center'>
						<input type='button' value='Register' onclick='commit()' name='btSubmit' />
						<input type='button' value='Reset' onclick='reset()' />
					</div>
				</form>";
$bodyEvents = "onload='pageLoad()'";
include("MasterPage.php");
?>
